<template>
    <div class="turn-tosend-dialog">
         <el-dialog
            title="转派三方"
            :visible.sync="turntosendShow"
            width="628px"
            :before-close="handleClose"
            :close-on-click-modal="false"
            custom-class="dialog-box">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
                <!-- 转派三方 -->
                <el-form-item label="评审任务名称" prop='taskName' >
                    <el-input  v-model="ruleForm.taskName" maxlength="32"></el-input>
                </el-form-item>
                <el-form-item label="选择第三方机构" prop="ormId" >
                    <el-select
                        v-model="ruleForm.ormId"
                        placeholder="请选择项目状态"
                        style="width:100%"
                    >
                        <el-option
                            v-for="item in manangmentList"
                            :key="item.ormId"
                            :label="item.organizationName"
                            :value="item.ormId"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item label="备注">
                    <el-input type="textarea" v-model="ruleForm.approvalOpinion"></el-input>
                </el-form-item>            
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="handleClose">取 消</el-button>
                <el-button type="primary" @click="submitForm">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import {getManagement,getTurnToThress} from '@/api/manage/manage'
    export default {
        name:'turntosendDialog',
        props: {
            turntosendShow: {
                type: Boolean,
                default: ''
            },
            type:{
                type: String,
                default: ''
            },
            proid:{
                type: String,
                default: ''
            },
            turntosendName:{
                type: String,
                default: ''
            }
        },
        inject:['reload'],
        data(){
            return{
                rules:{
                    taskName: [
                        { required: true, message: '请输入', trigger: 'blur' },
                    ],
                    ormId: [
                        { required: true, message: '请选择', trigger: 'change' ,},
                    ],
                },
                ruleForm:{
                    taskName:"",
                    ormId:'',
                },
                manangmentList:[]
            }
        },
        mounted(){
            
        },
        watch:{
            turntosendName(val){
                if(val){
                    this.getManagementList()
                    console.log(this.turntosendName)
                    this.$set(this.ruleForm,'taskName',this.turntosendName)
                }
            }
        },
        created(){
        },
        methods:{
                /** 取消按钮 */
            handleClose() {
            this.$refs.ruleForm.resetFields();
            this.$emit("changeShowDialog", "false"); //调用父组件的自定义事件，并传值
            },
            /** 确定按钮 */
            submitForm() {
                console.log(1)
                this.$refs.ruleForm.validate((valid) => {
                    if (valid) {
                        this.ruleForm.proid=this.proid
                        getTurnToThress(this.ruleForm).then(res =>{
                            console.log(res)  
                            if(res.code==200){
                                this.$message.success('操作成功')
                                this.$refs.ruleForm.resetFields();
                                this.$emit("changeShowDialog", "false");
                                this.reload()
                            }
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            getManagementList(){
                // if(this.turntosendShow){
                    getManagement().then(res =>{
                        console.log(res)
                        // if(res.code==200){
                            this.manangmentList=res
                        // }
                    })
                // }
                console.log(this.manangmentList)
            },
            
        } 
    }
</script>

<style lang="scss" >
.turn-tosend-dialog .dialog-box .el-form-item .el-input__inner {
  width: 100%;
}
.turn-tosend-dialog .dialog-box .el-form-item .el-textarea__inner {
  width: 100%;
}
</style>